import React from 'react';
import Loading from './Loading';
import { toJS } from 'mobx';

class Synergy extends React.Component {
    constructor() {
        super();
        this.state = { hasLoad: false };
    }
    componentDidMount() {
        const init = () => {
            this.setState({ hasLoad: true });
        };
        const portalFiles = [
            '/spa/portal/public/index.js',
            '/spa/portal/public/index.css',
            '/spa/portal/static/index.js',
            '/spa/portal/static/index.css',
        ];
        const loadjs = window.loadjs;
        loadjs.isDefined('f_portal') ? loadjs.ready('f_portal', init) : loadjs(portalFiles, 'f_portal', {
            async: false,
            success: init,
        });
    }
    render() {
        const { hasLoad } = this.state;
        if (hasLoad) {
            const { Synergy } = window.weaPortal;
            return (<Synergy ecId={`${this && this.props && this.props.ecId || ''}_Synergy@2rvh3s`} {...this.props} />);
        }
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@k0bgdx`} />);
    }
}

export { Synergy };
